import UnityEngine

class Txs_CameraMotor (MonoBehaviour):
	public characterMotor as Transform
	public rotSpeed as single = 3.0F 
	
	private y as single = 0.0F
	private minY as single = -80.0F
	private maxY as single = 80.0F

	def Start ():
		y = transform.eulerAngles.x
	
	def Update ():
		if Input.GetMouseButton(0):
			x = characterMotor.eulerAngles.y
			y += Input.GetAxis("Mouse Y")*rotSpeed
			y = ClampAngle(y,minY,maxY)

			camRotation = Quaternion.Euler(-y,x,0)
			transform.rotation = camRotation

	static def ClampAngle(angle as single, min as single, max as single):
		if(angle<-360):
			angle += 360
			
		if(angle>360):
			angle -= 360
			
		return Mathf.Clamp(angle,min,max)